package org.opentcs.kcvehicle.communication.kc.udp.agv.codec;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.nio.NioDatagramChannel;
import org.opentcs.kcvehicle.communication.kc.service.KCCommunicationImpl;

/**
 * 作者：蔡翔
 */
public class KCAgvUdpChannelInitializer
    extends
      ChannelInitializer<NioDatagramChannel> {
  private KCCommunicationImpl client;

  public KCAgvUdpChannelInitializer(KCCommunicationImpl client) {
    System.out.println(client.getHost());
    this.client = client;
  }



  @Override
  protected void initChannel(NioDatagramChannel channel)
      throws Exception {
    // Modbus
    // 在管道中添加我们自己的接收数据实现方法
    //todo 到时候这里改成  FixedLengthFrameDecoder  资料：https://www.cnblogs.com/java-chen-hao/p/11571229.html
//        channel.pipeline().addLast(
//                new LengthFieldBasedFrameDecoder(
//                200,
//                4,
//                2,
//                1,
//                7,
//                true)
//        );
    channel.pipeline().addLast(new KCAgvUdpDecode(this.client));  //InBoundHandler
    //channel.pipeline().addLast(new AgvUdpEncode());  //OutBoundHandler
  }
}
